
/// <reference path="./sinova/Collisions.ts" />

class Physics extends Collisions {



    static Scale = 1;
    static instance: Physics = null;

    private constructor(stage: egret.Stage) {
        super();
        this.debugDraw = new egret.Sprite();
        stage.addChild(this.debugDraw);
    }


    static create(stage: egret.Stage) {
        if (this.instance == null) {
            this.instance = new Physics(stage);
        }
        return this.instance;
    }

    debugDraw: egret.Sprite;

    draw() {
        this.debugDraw.graphics.clear();
        const bodies = this._bvh._bodies as BoxCollider[];
        const count = bodies.length;

        for (let i = 0; i < count; ++i) {
            bodies[i].render(this.debugDraw);
        }
    }


    addBody(...Bodies: Body[] | ICollider[]) {
        this.insert(...Bodies as SomeBody[]);
    }

    removeBody(...Bodies: Body[] | ICollider[]) {
        this.remove(...Bodies as SomeBody[]);
    }


}